
/*
 *  Copyright 2007 Marc Lanctot and Marc Gendron-Bellemare
 *
 *  This file is part of OpenMTG.
 *
 *  OpenMTG is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenMTG is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpenMTG.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


public class CardLoader 
{
  public CardLoader() 
  {
    // this will eventually connect to a database 
    // or load from files or something
  }

  public Card decode(String cardstring)
  {
    String[] cardparts = cardstring.split(","); 
    int cid = Integer.parseInt(cardparts[0]);
    int iid = Integer.parseInt(cardparts[1]);
    Card c = getCard(cid);
    c.setIID(iid);

    return c;
  }

  public Card getCard(int cid)
  {
    Card theCard = null; 

    switch(cid){
    case (9*Constants.MAX_SET_NUM+331):
      // plains
      theCard=new Card("Plains", new String[] {Card.TYPE_LAND});
      theCard.setCID(cid);
      break;
    case (9*Constants.MAX_SET_NUM+41):
      // savannah lions
      theCard = new Card("Savannah Lions", 
				new String[] {Card.TYPE_CREATURE}, "W", "Lion", 2, 1);
      theCard.addEffect(new CardEffect(Constants.EFTYPE_SUMMON, theCard));
      theCard.setCID(cid);
      break;
    case (9*Constants.MAX_SET_NUM+37):
      theCard = new Card("Mordak",
        new String[] {Card.TYPE_CREATURE}, "WW", "Wizard", 1, 3);
      theCard.addEffect(new CardEffect(Constants.EFTYPE_SUMMON, theCard));
      theCard.setCID(cid);
      break;
    case (9*Constants.MAX_SET_NUM+39):
      theCard = new Card("Whistler",
        new String[] {Card.TYPE_CREATURE}, "W", "Kitty", 0, 1);
      theCard.addEffect(new CardEffect(Constants.EFTYPE_SUMMON, theCard));
      theCard.setCID(cid);
      break;
    default:
      System.err.println("Unrecognized card value");
    }

    return theCard;
  }

}
